<!--
 * @Author: liuhanzhuang
 * @Date: 2023-01-09 17:21:53
 * @Description: 文件描述
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <style>
    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    body {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      background: linear-gradient(#eafbff 50%, #5290f9 50%);
    }

    .nav {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 70px;
      height: 70px;
      background-color: #fff;
      border-radius: 10px;
      transition: all .5s linear;
      overflow: hidden;
    }

    .nav.active {
      width: 380px;
    }

    .nav.active ul {
      width: calc(100% - 50px);
    }

    .nav.active li {
      opacity: 1;
      transform: rotateY(360deg);
    }

    .nav.active .line1 {
      transform: rotate(-756deg) translateY(5.5px);
    }

    .nav.active .line2 {
      transform: rotate(756deg) translateY(-5.5px);
    }

    a {
      text-decoration: none;
      color: #000;
      margin: 0 10px;
    }

    ul {
      list-style: none;
      display: flex;
      align-items: center;
      height: 100%;
      width: 0;
    }

    ul li {
      opacity: 0;
      transition: all .5s linear;
    }

    .icon {
      position: relative;
      width: 40px;
      height: 40px;
      border: none;
      background-color: #fff;
      cursor: pointer;
    }

    .icon .line {
      position: absolute;
      top: 15px;
      left: 20%;
      width: 25px;
      height: 2px;
      background-color: #5290f9;
      transition: all .5s linear;
    }

    .icon .line2 {
      top: 25px;
    }
  </style>
</head>

<body>
  <div class="nav">
    <ul>
      <li>
        <a href="#">Home</a>
      </li>
      <li>
        <a href="#">Works</a>
      </li>
      <li>
        <a href="#">About</a>
      </li>
      <li>
        <a href="#">Contact</a>
      </li>
    </ul>
    <button class="icon" id="toggle">
      <div class="line line1"></div>
      <div class="line line2"></div>
    </button>
  </div>
</body>
<script>
  let toggle = document.querySelector("#toggle");
  let nav = document.querySelector(".nav");
  toggle.addEventListener("click", () => {
    nav.classList.toggle("active");
  });
</script>

</html>